﻿using System.Web;
using Shinkansen.Support;

namespace Shinkansen.Runtime
{
    public class EncryptedQueryString : QueryString
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EncryptedQueryString"/> class.
        /// </summary>
        public EncryptedQueryString ()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EncryptedQueryString"/> class.
        /// </summary>
        /// <param name="queryString">The query string.</param>
        public EncryptedQueryString (string queryString) 
            : base (new Cryptography().Decrypt (HttpServerUtility.UrlTokenDecode (queryString))) 
        {
        }

        /// <summary>
        /// Toes the string.
        /// </summary>
        /// <returns></returns>
        public override string ToString ()
        {
            string qs = base.ToString ();
            return HttpServerUtility.UrlTokenEncode (new Cryptography ().Encrypt (qs));
        }
    }
}